<%@page import="tu.java.reservation.Ticket"%>
<%@page import="java.util.Vector"%>
<%@page import="tu.java.projection.Projection"%>
<%@page import="tu.java.reservation.Reservation"%>
<%@page import="tu.java.hall.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    
<%@include file="template/header.jspf" %>

<%	String pId = request.getParameter("pId");
	int hallSeatsCount=0;
	Projection vProjection = Projection.searchProjections(0, 0, "", "", Integer.parseInt(pId)).get(0);
	hallSeatsCount = vProjection.getHall().getHallSeatCount();
	Vector<HallSeat> hSeat= vProjection.getHall().getHallSeats();
%>
<script type="text/javascript"  src="<%=request.getContextPath()%>/js/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
	$("tbody td").click(function(e) {

		var id = this.getAttribute('id');
		
		if(id == 0)
		{
			return;
		}
		else if (this.style.getPropertyValue ("background-color") == "green")
		{
			this.style.removeProperty("background-color");
			document.getElementById("reservationform").removeChild(document.getElementById("reservationform").lastChild);
		}
		else
		{
			this.setAttribute("style", "background-color: green;");
			var node=document.createElement("input");
			node.setAttribute("type", "hidden");
			node.setAttribute("name", "reserved");
			node.setAttribute("value", id);
			document.getElementById("reservationform").appendChild(node);
			
			//alert(node.getAttribute("value"));
			//document.getElementById("seatId").setAttribute("value",document.getElementById("seatId").getAtribute("value")+ id);
		}
		
})});
</script>
<div  class="content">
	
	<h2 id="title">Резервация</h2>
		
	<table border="1"  id="seats">
		<% for(int j=0; j<(hallSeatsCount/10); j++){%>
		<tr	>
		<% for(int i=0; i<10; i++){
			int hallSeatId = hSeat.get(10*j +i).getHallSeatId();
			boolean one = false;
			Vector<Reservation> reservations = Reservation.searchReservationsForProjection(vProjection.getProjectionId());
			for(int x=0;x<reservations.size();x++){
				Vector<Ticket> tickets = reservations.get(x).getTickets();
				for(int y=0;y<tickets.size();y++){
					int seatId = tickets.get(y).getSeatId();
					if(seatId==hallSeatId){
						one = true;
					}
				}
			}
			if(one){
			%><td class="reserved" id="0"><%=hSeat.get(10*j +i).getSeatNum()%></td>		
			<%}else{%>
				<td id="<%=hSeat.get(10*j +i).getHallSeatId()%>"><%=hSeat.get(10*j +i).getSeatNum()%></td>	
			<%}			
		}%>
		</tr>
	<%}%>
	</table>
	
	 <form method="post" id="reservationform" action="<%=request.getContextPath()%>/confirm.jsp?pId=<%=pId%>"><br/>
		<input type="hidden" name="actn" value="">
 		<input type="submit" id="submit" name="submit" value="Запази" onclick="javascript:document.forms.reservationform.actn.value='next';"/>
	 </form>
</div>

<%@include file="template/footer.jspf" %>